package com.wyy.travels.service.impl;/*
 **
 * @author yangyang
 *@date 2022/07/19 22:06
 **/

import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import com.wyy.travels.dao.UserDao;
import com.wyy.travels.entity.User;
import com.wyy.travels.service.impl.UserDaoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@Slf4j
public class UserDaoServiceImpl implements  UserDaoService{
    @Autowired
    private UserDao userDao;
    @Override
    public void register(User user) {
        if (userDao.findByUsername(user.getUsername())==null){
            userDao.save(user);
        }else {
            throw  new RuntimeException("用户名已存在");
        }
    }

    @Override
    public User login(User user) {
        User byUsername = userDao.findByUsername(user.getUsername());
        if (byUsername!=null){
            if (byUsername.getPassword().equals(user.getPassword())){
                log.info("===byUsername====="+byUsername);
               return  byUsername;
            }
            throw  new RuntimeException("密码错误");
        }else{
            throw  new RuntimeException("用户名输入错误");
        }

    }
}
